package com.caroil.caroilservice.view.dialog;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

import com.caroil.caroilservice.R;

import androidx.annotation.Nullable;

/**
 * loading
 */
public class LoadingDialog extends LinearLayout {
    private LinearLayout progressbar;

    public LoadingDialog(Context context) {
        super(context);
        initView(context);
    }

    public LoadingDialog(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public LoadingDialog(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    public LoadingDialog(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        initView(context);
    }

    private void initView(Context context) {
        LayoutInflater mInflater = LayoutInflater.from(context);
        LinearLayout linearLayout = (LinearLayout) mInflater.inflate(
                R.layout.ld_loading, null);
        LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT);
        params.setMargins(0, 0, 0, 0);
        this.addView(linearLayout, params);
        progressbar = findViewById(R.id.pd);


    }

    public LinearLayout getView() {
        return progressbar;
    }

    /**
     * 显示
     */
    public void show() {
        progressbar.setVisibility(VISIBLE);
    }

    /**
     * 隐藏
     */
    public void dismiss() {
        progressbar.setVisibility(GONE);
    }
}
